/**单链表节点 */
export class ListNode {
    constructor(val, next) {
        this.val = (val === undefined ? 0 : val);
        this.next = (next === undefined ? null : next);
    }
}
/**数组转单链表 */
export function arrToList(arr) {
    if (!arr || arr.length === 0)
        return null;
    const head = new ListNode(0, null);
    let preNode = head;
    for (let i = 0; i < arr.length; i++) {
        const node = new ListNode(arr[i], null);
        preNode.next = node;
        preNode = node;
    }
    return head.next;
}
/**链表转数组 */
export function listToArr(node) {
    const res = [];
    while (node) {
        res.push(node.val);
        node = node.next;
    }
    return res;
}
